package com.gerald.shop.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gerald.shop.common.utils.PageUtils;
import com.gerald.shop.common.utils.Query;
import com.gerald.shop.entity.GoodsEntity;
import com.gerald.shop.dao.GoodsDao;
import com.gerald.shop.service.GoodsService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Map;

@Service("goodsService")
public class GoodsServiceImpl extends ServiceImpl<GoodsDao, GoodsEntity> implements GoodsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        //1 从param中获取封装分页参数
        IPage<GoodsEntity> pageParam = new Query<GoodsEntity>().getPage(params);

        //2 从param中获取条件查询
        QueryWrapper<GoodsEntity> queryWrapper = new QueryWrapper<>();
        Object key = params.get("key");
        if (!ObjectUtils.isEmpty(key)) {
            queryWrapper.like("gname", key);
        }

        // 3 设置分页条件和查询条件
        IPage<GoodsEntity> page = this.page(pageParam, queryWrapper);
        return new PageUtils(page);
    }

}
